﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jzy.Model.CRM;

using Jzy.DAL.CRM;

using Frame.Lib.Core.Base;
using Frame.Lib.Utilities;
using Frame.Lib.Core.User;

namespace Jzy.BLL.CRM
{
    public class CustomerBO : CommonOperate<CustomerInfo>
    {
        private CustomerDAL _customer;
        protected override BaseDAL DAL
        {
            get
            {
                return _customer;
            }
        }
        public CustomerBO()
        {
            _customer = new CustomerDAL();
        }

        public override CustomerInfo GetInfo(object id)
        {
            CustomerInfo info = base.GetInfo(id);

            info.GetContacts = customerID => (new CustomerContactBO()).GetList(customerID);
            info.GetVisits = customerID => (new CustomerVisitBO()).GetList(customerID);

            return info;
        }

        public override bool Exist(string name, object id)
        {
            return _customer.Exist(name, id);
        }

        public override bool ExistCode(string code, object id)
        {
            return _customer.ExistCode(code, id);
        }

        public void LogicDelete(string ids)
        {
            List<int> lstIDs = StrUtil.SplitToInt(ids);

            _customer.LogicDelete(lstIDs);
        }

        


        public void ChangeUser(string ids, int userID)
        {
            List<int> lstIDs = StrUtil.SplitToInt(ids);

            UserBO user = new UserBO();
            UserInfo info = user.GetInfo(userID);

            _customer.ChangeUser(lstIDs, info.ID, info.Name);
        }
    }
}
